package cn.car.controller;


import cn.car.biz.CameraBiz;
import cn.car.domains.vo.Result;
import cn.car.domains.vo.camera.CameraRes;
import cn.car.domains.vo.camera.CreateCameraReq;
import cn.car.domains.vo.camera.UpdateCameraReq;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@Tag(name = "cameraController",description = "相机管理相关接口")
@RequestMapping("/api/camera")
public class CameraController {

    @Resource
    private CameraBiz cameraBiz;

    /**
     * 创建相机
     */
    @PostMapping("/create")
    @Operation(description = "创建相机接口：根据请求参数创建一个新的相机设备")
    public Result<Void> createCamera(@RequestBody CreateCameraReq req) {
        cameraBiz.createCamera(req);
        return Result.success();
    }

    /**
     * 根据ID获取相机信息
     *
     * @param id 相机ID
     */
    @GetMapping("/getById")
    @Operation(description = "根据相机ID查询相机信息，返回相机详情")
    public Result<CameraRes> getCameraById(@RequestParam @Parameter(
            schema = @Schema(name = "id", description = "相机id")) Long id) {
        return Result.success(cameraBiz.getCameraById(id));
    }


    /**
     * 更新相机信息
     *
     * @param req 更新相机请求参数
     */
    @PostMapping("/update")
    @Operation(description = "更新相机信息接口：接收相机更新参数并保存变更")
    public Result<Void> updateCamera(@RequestBody UpdateCameraReq req) {
        cameraBiz.updateCamera(req);
        return Result.success();
    }

    /**
     * 删除相机
     *
     * @param id 相机ID
     */
    @PostMapping("/delete")
    @Operation(description = "删除相机接口：根据相机ID删除对应相机记录")
    public Result<Void> deleteCamera(@RequestParam @Parameter(
            schema = @Schema(name = "id", description = "相机id")) Long id) {
        cameraBiz.deleteCamera(id);
        return Result.success();
    }
}
